package com.xjc.business.controller.colladmin;

import com.xjc.business.entity.po.classadmin.ClassAdminExChangeDormitoryApplyOpera;
import com.xjc.business.entity.po.classadmin.ClassAdminLeaveApplyOpera;
import com.xjc.business.entity.vo.PageVo;
import com.xjc.business.entity.vo.classadmin.ClassExchangeDormitoryApplyVo;
import com.xjc.business.entity.vo.coladmin.ColExchangeDormitoryApplyVo;
import com.xjc.business.service.StudentChangeBedApplysService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 徐锦程
 * 时间:2025-02-07 19:18
 */
@RestController
@RequestMapping("/college_admin/exchange_apply")
public class CollegeExchangeDormitoryController {
    @Autowired
    StudentChangeBedApplysService studentChangeBedApplysService;

    /**
     * 获取换宿申请列表
     * @param pageSize 每页显示条数
     * @param currentPage 当前页
     * @param collegeAdminId 辅导员id
     * @param status 状态
     * @return Result
     */
    @GetMapping("/page/{pageSize}/{currentPage}")
    public Result<PageVo<ColExchangeDormitoryApplyVo>> getExchangeDormitoryApplyList(
            @PathVariable(value = "pageSize",required = false) Integer pageSize,
            @PathVariable(value = "currentPage",required = false) Integer currentPage,
            Integer collegeAdminId,
            Integer status
    ) {
        if(pageSize == null || pageSize <= 0){
            pageSize = 10;
        }
        if(currentPage == null || currentPage <= 0){
            currentPage = 1;
        }

        if(status == null){
            status = -1;
        }

        if(collegeAdminId == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentChangeBedApplysService.getExchangeDormitoryApplyListWithCollege(pageSize, currentPage, collegeAdminId, status);
    }

    /**
     * 学院管理员审批换宿申请
     * @param classAdminExChangeDormitoryApplyOpera 审批意见
     * @return Result
     */
    @PostMapping("/opera")
    public Result<String> leaveApplyOpera(@RequestBody(required = false) ClassAdminExChangeDormitoryApplyOpera classAdminExChangeDormitoryApplyOpera){
        if(classAdminExChangeDormitoryApplyOpera == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentChangeBedApplysService.changeDormitoryApplyOpera2(classAdminExChangeDormitoryApplyOpera);
    }
}
